{extend name="public:layout" /}
{block name='css'}
{/block}
{block name="content"}
<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 礼物管理 <span
            class="c-gray en">&gt;</span> 礼物列表<a class="btn btn-success radius r"
                                                 style="line-height:1.6em;margin-top:3px"
                                                 href="javascript:location.replace(location.href);" title="刷新"><i
            class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="text-c text-right">
                <input type="text" class="input-text" style="width:250px" placeholder="输入礼物名称/id" id="key" value="{$key|default=''}">
                <button type="submit" onclick="onSelect()" class="btn btn-success radius" name=""><i
                        class="Hui-iconfont">&#xe665;</i>
                    搜礼物
                </button>
                <a class="btn btn-primary radius" data-title="添加资讯" data-href="article-add.html" onclick="gift_add('添加','/gift/giftAdd','4','','510')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加礼物</a>
            </div>
            <div class="mt-20">
                <table class="table table-border table-bordered table-hover table-bg table-sort">
                    <thead>
                    <tr class="text-c">
                        <th width="80">ID</th>
                        <th width="80">礼物名称</th>
                        <th width="80">价格</th>
                        <th width="80">图标</th>
                        <th width="100">经验值</th>
                        <th width="90">状态</th>
                        <th width="70">更新日期</th>
                        <th width="100">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name='data' id='vo'}
                    <tr class="text-c">
                        <td>{$vo.id}</td>
                        <td>{$vo.name}</td>
                        <td>{$vo.money}</td>
                        <td>{$vo.icon}</td>
                        <td>{$vo.integral}</td>
                        <td class="td-status">
                        {if condition="$vo.status eq '正常'"}
                            <span class="label label-success radius">已发布</span>
                        {else /}
                            <span class="label label-defaunt radius">已下架</span>
                        {/if}
                        </td>
                        <!--<td>{}</td>-->
                        <td>{$vo.update_time}</td>
                        <td class="td-manage">
                            <a title="编辑" href="javascript:;" onclick="member_edit('编辑','/gift/giftEdit?id={$vo.id}','4','','510')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                            <a style="text-decoration:none" class="ml-5" onClick="picture_del(this,{$vo.id})" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
            {$data->render()}
        </article>
    </div>
</section>
{/block}

{block name='js'}
<script type="text/javascript">
    function onSelect() {
        let key = $("#key").val();
        location.href = "{:url('gift/giftList')}"+"?key="+key;
    }
    /*编辑*/
    function member_edit(title, url, id, w, h) {
        layer_show(title, url, w, h);
    }

    /*添加*/
    function gift_add(title, url, id, w, h) {
        layer_show(title, url, w, h);
    }
    /*删除*/
    function picture_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'GET',
                url: "{:url('gift/giftDel')}"+'?id='+id,
                dataType: 'json',
                success: function(data){
                    var message = $.parseJSON(data).message;
                    var status = $.parseJSON(data).status;
                    if (status == 1){
                        $(obj).parents("tr").remove();
                        layer.msg(message,{icon:1,time:1000});
                    } else{
                        layer.msg(message,{icon:5,time:1000});
                    }
                },
                error:function(data) {
                    console.log(data.message);
                },
            });
        });
    }
</script>
{/block}
